/**
 *  Copyright 2010 Kyle O'Connor, Justin Arling, Mike Mercieca
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package edu.drexel.sd0910.ece01.aqmon.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Utility methods for custom string manipulation and regular expressions.
 * 
 * @author Kyle O'Connor
 * 
 */
public class StringUtils {

	/**
	 * Utils class can not be instantiated.
	 */
	private StringUtils() { }

	/**
	 * Tests to see if the given name is acceptable. Acceptable for this method
	 * is if the string contains only alphanumeric, underscore, dash, period, or
	 * space characters.
	 * 
	 * @param name
	 *            the given name as <code>String</code>
	 * @return true, if the name is acceptable as defined by this method, false,
	 *         otherwise.
	 */
	public static boolean isAcceptableName(final String name) {
		Pattern p = Pattern.compile("[\\w\\.\\- ]+");
		Matcher m = p.matcher(name);
		if (m.matches()) {
			return true;
		}
		return false;
	}

	public static void main(String[] args) {
		System.out.println("Norris Square" + " :: " + isAcceptableName("Norris Square"));
		System.out.println("Hutning Park" + " :: " + isAcceptableName("Hutning Park"));
		System.out.println("Test Deployment 05.14.10" + " :: " + isAcceptableName("Test Deployment 05.14.10"));
		System.out.println("Test Deployment 05.14.10:" + " :: " + isAcceptableName("Test Deployment 05.14.10:"));
		System.out.println("@Test" + " :: " + isAcceptableName("@Test"));
		System.out.println("Test this (thing)" + " :: " + isAcceptableName("Test this (thing)"));
		System.out.println("Test this.deploy" + " :: " + isAcceptableName("Test this.deploy"));
		System.out.println("Test      ".trim() + " :: " + isAcceptableName("Test      ".trim()));
		System.out.println("Test  %   ".trim() + " :: " + isAcceptableName("Test  %   ".trim()));
		System.out.println("$" + " :: " + isAcceptableName("$"));
	}

}
